##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
Confusion matrix - Imputed Shapes
#Predict the class
imputed_match_df$pred <- names(imputed_match_df[,1:7])[apply(imputed_match_df[,1:7],1,which.max)]
table(factor(imputed_match_df$true,levels = c("Alcelaphini", "Antilopini", "Tragelaphini", "Neotragini","Bovini", "Reduncini", "Hippotragini" )),factor(imputed_match_df$pred, levels = c("Alcelaphini", "Antilopini", "Tragelaphini", "Neotragini","Bovini", "Reduncini", "Hippotragini" )))
##
## Alcelaphini Antilopini Tragelaphini Neotragini Bovini
## Alcelaphini 104 0 0 2 0
## Antilopini 0 27 0 0 0
## Tragelaphini 1 1 50 14 0
## Neotragini 0 1 0 44 0
## Bovini 7 1 4 0 0
## Reduncini 3 1 1 10 0
## Hippotragini 7 0 0 1 0
##
## Reduncini Hippotragini
## Alcelaphini 0 0
## Antilopini 0 0
## Tragelaphini 0 0
## Neotragini 0 0
## Bovini 9 1
## Reduncini 61 0
## Hippotragini 17 1
Confusion matrix - No Imputation
part_match_df$pred <- names(part_match_df[,1:7])[apply(part_match_df[,1:7],1,which.max)]
table(factor(part_match_df$true,levels = c("Alcelaphini", "Antilopini", "Tragelaphini", "Neotragini","Bovini", "Reduncini", "Hippotragini" )),factor(part_match_df$pred, levels = c("Alcelaphini", "Antilopini", "Tragelaphini", "Neotragini","Bovini", "Reduncini", "Hippotragini" )))
##
## Alcelaphini Antilopini Tragelaphini Neotragini Bovini
## Alcelaphini 103 1 0 0 0
## Antilopini 0 27 0 0 0
## Tragelaphini 3 1 55 7 0
## Neotragini 0 3 1 40 0
## Bovini 2 0 5 0 4
## Reduncini 8 0 0 1 0
## Hippotragini 6 0 0 0 0
##
## Reduncini Hippotragini
## Alcelaphini 2 0
## Antilopini 0 0
## Tragelaphini 0 0
## Neotragini 1 0
## Bovini 8 3
## Reduncini 67 0
## Hippotragini 17 3
ROC Analysis - One class at a time Imputed - Blue, No Imputation - Red
#ROC analysis
for (q in c("Alcelaphini","Antilopini","Bovini","Hippotragini","Neotragini","Reduncini","Tragelaphini")){
temp <- imputed_match_df
tribe <- q
temp$true <- as.character(temp$true)
temp$true[(temp$true) != tribe] <- 0
temp$true[(temp$true) == tribe] <- 1
library(ROCR)
pred <- prediction(temp[[tribe]], as.numeric(temp$true))
perf <- performance(pred, measure = "tpr", x.measure = "fpr")
plot(perf, col="blue", main = tribe)
temp <- part_match_df
temp$true <- as.character(temp$true)
temp$true[(temp$true) != tribe] <- 0
temp$true[(temp$true) == tribe] <- 1
library(ROCR)
pred <- prediction(temp[[tribe]], as.numeric(temp$true))
perf <- performance(pred, measure = "tpr", x.measure = "fpr")
plot(perf, col="red", add = TRUE, lty = 3)
}
## Loading required package: gplots
## Warning: package 'gplots' was built under R version 3.5.2
##
## Attaching package: 'gplots'
## The following object is masked from 'package:stats':
##
## lowess
Predicting Species
load("/Users/gregorymatthews/Dropbox/shapeanalysisgit/results/results20190610_side=1_k=5_M=5_tooth=LM1_summaries_species.RData")
fret <- data.frame(logloss = c(logloss_imputed,logloss_part), k = c(1:20,1:20), method = c(rep("knn w Imputation",20),rep("knn no imputation",20)))
library(ggplot2)
ggplot(aes(x = k, y = logloss, col = method), data = fret) + geom_point() + geom_line()
fret <- data.frame(true_pred_prob_imputed = imputed_match_df$true_pred_prob, true_pred_prob_part = part_match_df$true_pred_prob, true = imputed_match_df$true)
hull_spec <- fret %>%
group_by(true) %>%
slice(chull(true_pred_prob_imputed, true_pred_prob_part))
# Update the plot with a fill group, and overlay the new hulls
#p + aes(fill = factor(cyl)) + geom_polygon(data = hull_cyl, alpha = 0.5)
ggplot(aes(x = true_pred_prob_imputed, y = true_pred_prob_part, col = true), data = fret) + geom_point() + geom_polygon(data = hull_spec, alpha = 0)
Confusion matrix - Imputed Shapes
#Predict the class
spec <- c("buselaphus","dorcas","gnou","taurinus", "marsupialis","oryx","scriptus","strepsiceros", "campestris","capreolus","oreotragus","ourebi","caffer", "arundinum","ellipsiprymnus","fulvorufulva","leche", "equinus","gazella","niger")
imputed_match_df$pred <- names(imputed_match_df[,1:20])[apply(imputed_match_df[,1:20],1,which.max)]
table(factor(imputed_match_df$true,levels = spec),factor(imputed_match_df$pred, levels = spec))
##
## buselaphus dorcas gnou taurinus marsupialis oryx scriptus
## buselaphus 11 4 3 4 0 0 0
## dorcas 2 22 3 0 0 0 2
## gnou 0 5 17 7 1 0 0
## taurinus 3 1 15 5 0 0 0
## marsupialis 0 0 0 0 27 0 0
## oryx 0 0 0 0 0 2 0
## scriptus 0 0 0 0 1 0 21
## strepsiceros 0 0 0 0 0 0 0
## campestris 0 0 0 0 1 0 0
## capreolus 0 0 0 0 2 0 5
## oreotragus 0 0 0 0 0 0 0
## ourebi 0 0 0 0 0 0 0
## caffer 2 1 0 0 4 0 0
## arundinum 0 0 1 0 1 0 1
## ellipsiprymnus 0 0 1 0 0 0 0
## fulvorufulva 0 1 0 0 0 0 1
## leche 0 0 0 0 2 0 0
## equinus 1 0 0 0 1 0 0
## gazella 3 1 0 0 0 0 0
## niger 2 0 0 0 1 0 0
##
## strepsiceros campestris capreolus oreotragus ourebi
## buselaphus 0 0 0 0 0
## dorcas 0 0 0 1 0
## gnou 0 0 0 0 0
## taurinus 0 0 0 0 0
## marsupialis 0 0 0 0 0
## oryx 16 0 0 0 0
## scriptus 0 5 0 1 0
## strepsiceros 19 0 0 0 0
## campestris 0 12 0 2 0
## capreolus 0 0 0 2 0
## oreotragus 0 9 0 3 0
## ourebi 0 7 0 2 0
## caffer 5 0 0 0 0
## arundinum 0 3 0 0 0
## ellipsiprymnus 1 0 0 0 0
## fulvorufulva 0 1 0 0 0
## leche 0 0 0 1 0
## equinus 0 0 0 0 0
## gazella 0 0 0 0 0
## niger 0 0 0 0 0
##
## caffer arundinum ellipsiprymnus fulvorufulva leche
## buselaphus 0 0 0 0 0
## dorcas 0 0 0 0 0
## gnou 0 0 0 0 0
## taurinus 0 0 0 0 0
## marsupialis 0 0 0 0 0
## oryx 0 0 1 0 0
## scriptus 0 0 0 0 0
## strepsiceros 0 0 0 0 0
## campestris 0 0 0 0 0
## capreolus 0 0 0 0 0
## oreotragus 0 0 0 0 0
## ourebi 0 0 0 0 0
## caffer 4 2 1 0 2
## arundinum 0 7 0 0 5
## ellipsiprymnus 0 0 14 0 8
## fulvorufulva 0 5 0 4 0
## leche 0 3 0 0 16
## equinus 0 0 2 0 3
## gazella 0 0 2 0 0
## niger 0 1 2 0 4
##
## equinus gazella niger
## buselaphus 0 0 0
## dorcas 0 0 0
## gnou 0 0 0
## taurinus 0 0 0
## marsupialis 0 0 0
## oryx 0 0 0
## scriptus 0 0 0
## strepsiceros 0 0 0
## campestris 0 0 0
## capreolus 0 0 0
## oreotragus 0 0 0
## ourebi 0 0 0
## caffer 0 0 1
## arundinum 0 0 0
## ellipsiprymnus 0 0 0
## fulvorufulva 0 0 0
## leche 0 0 0
## equinus 0 0 1
## gazella 0 0 0
## niger 1 0 1
Confusion matrix - No Imputation
#Predict the class
spec <- c("buselaphus","dorcas","gnou","taurinus", "marsupialis","oryx","scriptus","strepsiceros", "campestris","capreolus","oreotragus","ourebi","caffer", "arundinum","ellipsiprymnus","fulvorufulva","leche", "equinus","gazella","niger")
part_match_df$pred <- names(part_match_df[,1:20])[apply(part_match_df[,1:20],1,which.max)]
table(factor(part_match_df$true,levels = spec),factor(part_match_df$pred, levels = spec))
##
## buselaphus dorcas gnou taurinus marsupialis oryx scriptus
## buselaphus 10 5 7 0 0 0 0
## dorcas 0 22 4 0 3 0 1
## gnou 0 1 25 2 0 0 0
## taurinus 4 0 15 5 0 0 0
## marsupialis 0 0 0 0 27 0 0
## oryx 0 0 1 0 0 11 0
## scriptus 0 0 0 0 1 0 26
## strepsiceros 0 0 1 0 0 0 0
## campestris 0 0 0 0 1 0 0
## capreolus 0 0 0 0 2 0 6
## oreotragus 0 0 0 0 0 0 0
## ourebi 0 0 0 0 0 0 3
## caffer 1 0 1 0 0 2 0
## arundinum 0 3 0 0 0 0 0
## ellipsiprymnus 0 0 1 0 0 0 0
## fulvorufulva 0 1 0 0 0 0 0
## leche 0 0 0 0 1 0 0
## equinus 0 0 0 0 0 0 0
## gazella 1 0 1 2 0 0 0
## niger 1 0 1 0 0 0 0
##
## strepsiceros campestris capreolus oreotragus ourebi
## buselaphus 0 0 0 0 0
## dorcas 0 0 0 0 0
## gnou 0 0 0 0 0
## taurinus 0 0 0 0 0
## marsupialis 0 0 0 0 0
## oryx 7 0 0 0 0
## scriptus 0 1 0 0 0
## strepsiceros 18 0 0 0 0
## campestris 0 11 0 3 0
## capreolus 0 0 0 0 0
## oreotragus 0 6 0 6 0
## ourebi 0 2 0 1 3
## caffer 1 0 0 0 0
## arundinum 0 0 0 0 0
## ellipsiprymnus 0 0 0 0 0
## fulvorufulva 0 0 0 0 1
## leche 0 0 0 0 0
## equinus 0 0 0 0 0
## gazella 0 0 0 0 0
## niger 0 0 0 0 0
##
## caffer arundinum ellipsiprymnus fulvorufulva leche
## buselaphus 0 0 0 0 0
## dorcas 0 0 0 0 0
## gnou 0 0 0 0 2
## taurinus 0 0 0 0 0
## marsupialis 0 0 0 0 0
## oryx 0 0 0 0 0
## scriptus 0 0 0 0 0
## strepsiceros 0 0 0 0 0
## campestris 0 0 0 0 0
## capreolus 0 0 0 1 0
## oreotragus 0 0 0 0 0
## ourebi 0 0 0 0 0
## caffer 8 0 9 0 0
## arundinum 0 9 0 1 5
## ellipsiprymnus 0 0 19 0 4
## fulvorufulva 0 6 0 4 0
## leche 0 1 0 1 19
## equinus 0 0 6 0 2
## gazella 0 0 2 0 0
## niger 0 1 8 0 1
##
## equinus gazella niger
## buselaphus 0 0 0
## dorcas 0 0 0
## gnou 0 0 0
## taurinus 0 0 0
## marsupialis 0 0 0
## oryx 0 0 0
## scriptus 0 0 0
## strepsiceros 0 0 0
## campestris 0 0 0
## capreolus 0 0 0
## oreotragus 0 0 0
## ourebi 0 0 0
## caffer 0 0 0
## arundinum 0 0 0
## ellipsiprymnus 0 0 0
## fulvorufulva 0 0 0
## leche 0 0 0
## equinus 0 0 0
## gazella 0 0 0
## niger 0 0 0
Confusion matrix - Imputed Shapes
#Predict the class
imputed_match_df$pred <- names(imputed_match_df[,1:7])[apply(imputed_match_df[,1:7],1,which.max)]
table(factor(imputed_match_df$true,levels = c("Alcelaphini", "Antilopini", "Tragelaphini", "Neotragini","Bovini", "Reduncini", "Hippotragini" )),factor(imputed_match_df$pred, levels = c("Alcelaphini", "Antilopini", "Tragelaphini", "Neotragini","Bovini", "Reduncini", "Hippotragini" )))
##
## Alcelaphini Antilopini Tragelaphini Neotragini Bovini
## Alcelaphini 103 0 0 1 0
## Antilopini 0 26 0 1 0
## Tragelaphini 2 1 45 15 0
## Neotragini 0 0 0 45 0
## Bovini 2 1 1 0 3
## Reduncini 2 2 0 7 0
## Hippotragini 0 0 1 0 0
##
## Reduncini Hippotragini
## Alcelaphini 1 1
## Antilopini 0 0
## Tragelaphini 1 2
## Neotragini 0 0
## Bovini 7 8
## Reduncini 60 5
## Hippotragini 18 7
Confusion matrix - No Imputation
part_match_df$pred <- names(part_match_df[,1:7])[apply(part_match_df[,1:7],1,which.max)]
table(factor(part_match_df$true,levels = c("Alcelaphini", "Antilopini", "Tragelaphini", "Neotragini","Bovini", "Reduncini", "Hippotragini" )),factor(part_match_df$pred, levels = c("Alcelaphini", "Antilopini", "Tragelaphini", "Neotragini","Bovini", "Reduncini", "Hippotragini" )))
##
## Alcelaphini Antilopini Tragelaphini Neotragini Bovini
## Alcelaphini 105 0 0 0 0
## Antilopini 0 27 0 0 0
## Tragelaphini 2 0 45 15 0
## Neotragini 0 0 0 44 0
## Bovini 5 0 0 0 14
## Reduncini 0 0 0 0 0
## Hippotragini 0 0 1 0 0
##
## Reduncini Hippotragini
## Alcelaphini 1 0
## Antilopini 0 0
## Tragelaphini 4 0
## Neotragini 1 0
## Bovini 2 1
## Reduncini 71 5
## Hippotragini 15 10
ROC Analysis - One class at a time Imputed - Blue, No Imputation - Red
#ROC analysis
for (q in c("Alcelaphini","Antilopini","Bovini","Hippotragini","Neotragini","Reduncini","Tragelaphini")){
temp <- imputed_match_df
tribe <- q
temp$true <- as.character(temp$true)
temp$true[(temp$true) != tribe] <- 0
temp$true[(temp$true) == tribe] <- 1
library(ROCR)
pred <- prediction(temp[[tribe]], as.numeric(temp$true))
perf <- performance(pred, measure = "tpr", x.measure = "fpr")
plot(perf, col="blue", main = tribe)
temp <- part_match_df
temp$true <- as.character(temp$true)
temp$true[(temp$true) != tribe] <- 0
temp$true[(temp$true) == tribe] <- 1
library(ROCR)
pred <- prediction(temp[[tribe]], as.numeric(temp$true))
perf <- performance(pred, measure = "tpr", x.measure = "fpr")
plot(perf, col="red", add = TRUE, lty = 3)
}
Predicting Species
load("/Users/gregorymatthews/Dropbox/shapeanalysisgit/results/results20190610_side=2_k=5_M=5_tooth=LM1_summaries_species.RData")
fret <- data.frame(logloss = c(logloss_imputed,logloss_part), k = c(1:20,1:20), method = c(rep("knn w Imputation",20),rep("knn no imputation",20)))
library(ggplot2)
ggplot(aes(x = k, y = logloss, col = method), data = fret) + geom_point() + geom_line()
Confusion matrix - Imputed Shapes
#Predict the class
spec <- c("buselaphus","dorcas","gnou","taurinus", "marsupialis","oryx","scriptus","strepsiceros", "campestris","capreolus","oreotragus","ourebi","caffer", "arundinum","ellipsiprymnus","fulvorufulva","leche", "equinus","gazella","niger")
imputed_match_df$pred <- names(imputed_match_df[,1:20])[apply(imputed_match_df[,1:20],1,which.max)]
table(factor(imputed_match_df$true,levels = spec),factor(imputed_match_df$pred, levels = spec))
##
## buselaphus dorcas gnou taurinus marsupialis oryx scriptus
## buselaphus 11 9 2 0 0 0 0
## dorcas 1 26 2 0 0 0 1
## gnou 4 1 20 3 1 0 0
## taurinus 3 3 9 9 0 0 0
## marsupialis 0 0 0 0 27 0 0
## oryx 0 1 0 0 1 3 0
## scriptus 0 0 0 0 0 1 16
## strepsiceros 1 0 0 0 0 0 0
## campestris 0 0 0 0 1 0 0
## capreolus 0 0 0 0 2 0 2
## oreotragus 0 0 0 0 0 0 0
## ourebi 0 0 0 0 0 0 0
## caffer 1 0 0 0 1 0 0
## arundinum 0 1 0 0 0 0 0
## ellipsiprymnus 0 0 0 0 1 0 0
## fulvorufulva 0 0 0 0 0 0 0
## leche 0 0 0 0 2 0 0
## equinus 0 0 0 0 1 0 0
## gazella 0 0 0 0 0 0 0
## niger 0 0 0 0 0 0 0
##
## strepsiceros campestris capreolus oreotragus ourebi
## buselaphus 0 0 0 0 0
## dorcas 0 0 0 0 0
## gnou 0 0 0 0 0
## taurinus 0 0 0 0 0
## marsupialis 0 0 0 0 0
## oryx 12 0 0 0 0
## scriptus 0 7 0 3 0
## strepsiceros 18 0 0 0 0
## campestris 0 14 0 0 0
## capreolus 0 1 0 4 0
## oreotragus 0 9 0 3 0
## ourebi 0 9 0 0 0
## caffer 0 0 0 0 0
## arundinum 0 0 0 2 0
## ellipsiprymnus 0 0 0 0 0
## fulvorufulva 0 1 0 0 0
## leche 0 0 0 0 0
## equinus 0 0 0 0 0
## gazella 0 0 0 0 0
## niger 0 0 0 0 0
##
## caffer arundinum ellipsiprymnus fulvorufulva leche
## buselaphus 0 0 0 0 0
## dorcas 0 0 0 0 0
## gnou 0 0 1 0 0
## taurinus 0 0 0 0 0
## marsupialis 0 0 0 0 0
## oryx 0 0 1 0 0
## scriptus 1 0 0 0 0
## strepsiceros 0 0 0 0 0
## campestris 0 0 0 0 0
## capreolus 0 0 0 0 0
## oreotragus 0 0 0 0 0
## ourebi 0 0 0 0 0
## caffer 15 0 2 0 0
## arundinum 0 12 0 0 3
## ellipsiprymnus 0 1 14 0 2
## fulvorufulva 0 3 0 4 4
## leche 0 12 0 0 8
## equinus 0 0 2 0 1
## gazella 1 2 3 0 0
## niger 0 2 5 0 0
##
## equinus gazella niger
## buselaphus 0 0 0
## dorcas 0 0 0
## gnou 0 0 0
## taurinus 0 0 0
## marsupialis 0 0 0
## oryx 0 0 1
## scriptus 0 0 0
## strepsiceros 0 0 0
## campestris 0 0 0
## capreolus 0 0 0
## oreotragus 0 0 0
## ourebi 0 0 0
## caffer 1 1 1
## arundinum 0 0 0
## ellipsiprymnus 0 0 6
## fulvorufulva 0 0 0
## leche 0 0 0
## equinus 0 0 4
## gazella 0 0 0
## niger 0 0 5
Confusion matrix - No Imputation
#Predict the class
spec <- c("buselaphus","dorcas","gnou","taurinus", "marsupialis","oryx","scriptus","strepsiceros", "campestris","capreolus","oreotragus","ourebi","caffer", "arundinum","ellipsiprymnus","fulvorufulva","leche", "equinus","gazella","niger")
part_match_df$pred <- names(part_match_df[,1:20])[apply(part_match_df[,1:20],1,which.max)]
table(factor(part_match_df$true,levels = spec),factor(part_match_df$pred, levels = spec))
##
## buselaphus dorcas gnou taurinus marsupialis oryx scriptus
## buselaphus 14 6 2 0 0 0 0
## dorcas 0 29 1 0 0 0 0
## gnou 1 2 26 0 0 0 0
## taurinus 4 0 12 8 0 0 0
## marsupialis 0 0 0 0 27 0 0
## oryx 0 0 0 0 0 10 0
## scriptus 0 0 1 0 0 0 19
## strepsiceros 0 0 0 0 0 1 0
## campestris 0 0 0 0 0 0 0
## capreolus 0 0 0 0 1 0 5
## oreotragus 0 0 0 0 0 0 0
## ourebi 0 0 0 0 0 0 3
## caffer 3 0 0 0 0 0 0
## arundinum 0 0 0 0 0 0 0
## ellipsiprymnus 0 0 0 0 0 0 0
## fulvorufulva 0 1 0 0 0 0 0
## leche 0 0 0 0 0 0 0
## equinus 0 0 0 0 0 0 0
## gazella 0 0 0 0 0 0 0
## niger 0 0 0 0 0 0 0
##
## strepsiceros campestris capreolus oreotragus ourebi
## buselaphus 0 0 0 0 0
## dorcas 0 0 0 0 0
## gnou 0 0 0 0 0
## taurinus 0 0 0 0 0
## marsupialis 0 0 0 0 0
## oryx 5 0 0 0 0
## scriptus 0 4 0 3 0
## strepsiceros 18 0 0 0 0
## campestris 0 12 1 2 0
## capreolus 0 0 0 3 0
## oreotragus 0 5 0 7 0
## ourebi 0 2 0 1 2
## caffer 0 0 0 0 0
## arundinum 0 0 0 0 0
## ellipsiprymnus 0 0 0 0 0
## fulvorufulva 0 0 0 0 0
## leche 0 0 0 0 0
## equinus 1 0 0 0 0
## gazella 0 0 0 0 0
## niger 0 0 0 0 0
##
## caffer arundinum ellipsiprymnus fulvorufulva leche
## buselaphus 0 0 0 0 0
## dorcas 0 0 0 0 0
## gnou 0 0 0 0 1
## taurinus 0 0 0 0 0
## marsupialis 0 0 0 0 0
## oryx 0 0 4 0 0
## scriptus 1 0 0 0 0
## strepsiceros 0 0 0 0 0
## campestris 0 0 0 0 0
## capreolus 0 0 0 0 0
## oreotragus 0 0 0 0 0
## ourebi 0 1 0 0 0
## caffer 16 0 3 0 0
## arundinum 0 11 0 0 7
## ellipsiprymnus 0 0 22 0 0
## fulvorufulva 0 6 0 4 1
## leche 0 4 0 0 18
## equinus 0 0 6 0 0
## gazella 0 0 6 0 0
## niger 0 0 8 0 1
##
## equinus gazella niger
## buselaphus 0 0 0
## dorcas 0 0 0
## gnou 0 0 0
## taurinus 0 0 0
## marsupialis 0 0 0
## oryx 0 0 0
## scriptus 0 0 0
## strepsiceros 0 0 0
## campestris 0 0 0
## capreolus 0 0 0
## oreotragus 0 0 0
## ourebi 0 0 0
## caffer 0 0 0
## arundinum 0 0 0
## ellipsiprymnus 0 0 2
## fulvorufulva 0 0 0
## leche 0 0 0
## equinus 0 0 1
## gazella 0 0 0
## niger 0 0 3
Confusion matrix - Imputed Shapes
#Predict the class
imputed_match_df$pred <- names(imputed_match_df[,1:7])[apply(imputed_match_df[,1:7],1,which.max)]
table(factor(imputed_match_df$true,levels = c("Alcelaphini", "Antilopini", "Tragelaphini", "Neotragini","Bovini", "Reduncini", "Hippotragini" )),factor(imputed_match_df$pred, levels = c("Alcelaphini", "Antilopini", "Tragelaphini", "Neotragini","Bovini", "Reduncini", "Hippotragini" )))
##
## Alcelaphini Antilopini Tragelaphini Neotragini Bovini
## Alcelaphini 117 0 0 0 0
## Antilopini 3 22 2 3 0
## Tragelaphini 7 1 35 19 0
## Neotragini 0 0 4 52 0
## Bovini 12 0 4 0 2
## Reduncini 0 0 1 3 0
## Hippotragini 2 0 1 2 0
##
## Reduncini Hippotragini
## Alcelaphini 0 0
## Antilopini 0 0
## Tragelaphini 0 0
## Neotragini 0 0
## Bovini 1 0
## Reduncini 92 0
## Hippotragini 29 0
Confusion matrix - No Imputation
part_match_df$pred <- names(part_match_df[,1:7])[apply(part_match_df[,1:7],1,which.max)]
table(factor(part_match_df$true,levels = c("Alcelaphini", "Antilopini", "Tragelaphini", "Neotragini","Bovini", "Reduncini", "Hippotragini" )),factor(part_match_df$pred, levels = c("Alcelaphini", "Antilopini", "Tragelaphini", "Neotragini","Bovini", "Reduncini", "Hippotragini" )))
##
## Alcelaphini Antilopini Tragelaphini Neotragini Bovini
## Alcelaphini 116 1 0 0 0
## Antilopini 3 25 2 0 0
## Tragelaphini 2 2 56 2 0
## Neotragini 2 0 8 45 0
## Bovini 10 0 3 0 6
## Reduncini 2 0 1 0 0
## Hippotragini 2 0 1 0 0
##
## Reduncini Hippotragini
## Alcelaphini 0 0
## Antilopini 0 0
## Tragelaphini 0 0
## Neotragini 0 1
## Bovini 0 0
## Reduncini 91 2
## Hippotragini 22 9
ROC Analysis - One class at a time Imputed - Blue, No Imputation - Red
#ROC analysis
for (q in c("Alcelaphini","Antilopini","Bovini","Hippotragini","Neotragini","Reduncini","Tragelaphini")){
temp <- imputed_match_df
tribe <- q
temp$true <- as.character(temp$true)
temp$true[(temp$true) != tribe] <- 0
temp$true[(temp$true) == tribe] <- 1
library(ROCR)
pred <- prediction(temp[[tribe]], as.numeric(temp$true))
perf <- performance(pred, measure = "tpr", x.measure = "fpr")
plot(perf, col="blue", main = tribe)
temp <- part_match_df
temp$true <- as.character(temp$true)
temp$true[(temp$true) != tribe] <- 0
temp$true[(temp$true) == tribe] <- 1
library(ROCR)
pred <- prediction(temp[[tribe]], as.numeric(temp$true))
perf <- performance(pred, measure = "tpr", x.measure = "fpr")
plot(perf, col="red", add = TRUE, lty = 3)
}
Predicting Species
load("/Users/gregorymatthews/Dropbox/shapeanalysisgit/results/results20190610_side=1_k=5_M=5_tooth=LM3_summaries_species.RData")
fret <- data.frame(logloss = c(logloss_imputed,logloss_part), k = c(1:20,1:20), method = c(rep("knn w Imputation",20),rep("knn no imputation",20)))
library(ggplot2)
ggplot(aes(x = k, y = logloss, col = method), data = fret) + geom_point() + geom_line()
Confusion matrix - Imputed Shapes
#Predict the class
spec <- c("buselaphus","dorcas","gnou","taurinus", "marsupialis","oryx","scriptus","strepsiceros", "campestris","capreolus","oreotragus","ourebi","caffer", "arundinum","ellipsiprymnus","fulvorufulva","leche", "equinus","gazella","niger")
imputed_match_df$pred <- names(imputed_match_df[,1:20])[apply(imputed_match_df[,1:20],1,which.max)]
table(factor(imputed_match_df$true,levels = spec),factor(imputed_match_df$pred, levels = spec))
##
## buselaphus dorcas gnou taurinus marsupialis oryx scriptus
## buselaphus 13 7 11 0 0 0 0
## dorcas 0 29 2 0 0 0 0
## gnou 6 4 20 0 0 0 0
## taurinus 8 2 13 2 0 0 0
## marsupialis 0 2 0 0 27 0 1
## oryx 1 1 1 1 0 15 0
## scriptus 0 0 0 0 0 0 19
## strepsiceros 0 1 1 0 3 3 1
## campestris 0 0 0 0 0 2 0
## capreolus 0 0 0 0 0 0 3
## oreotragus 0 0 0 0 0 0 0
## ourebi 0 0 0 0 0 0 1
## caffer 3 0 4 1 0 2 0
## arundinum 0 0 0 0 0 0 0
## ellipsiprymnus 0 0 0 0 1 0 0
## fulvorufulva 0 0 0 0 0 0 2
## leche 0 0 0 0 0 0 0
## equinus 0 0 0 0 1 0 0
## gazella 0 0 1 0 0 0 0
## niger 0 0 0 0 2 0 0
##
## strepsiceros campestris capreolus oreotragus ourebi
## buselaphus 0 0 0 0 0
## dorcas 0 0 0 0 0
## gnou 0 0 0 0 0
## taurinus 0 0 0 0 0
## marsupialis 0 0 0 0 0
## oryx 1 0 0 0 0
## scriptus 0 2 0 1 0
## strepsiceros 11 0 0 0 0
## campestris 1 23 0 0 0
## capreolus 0 5 0 1 0
## oreotragus 0 12 0 0 0
## ourebi 0 8 0 0 0
## caffer 2 0 0 0 0
## arundinum 0 0 0 0 0
## ellipsiprymnus 0 1 0 0 0
## fulvorufulva 0 0 0 0 0
## leche 0 0 0 0 0
## equinus 0 1 0 0 0
## gazella 1 0 0 0 0
## niger 0 1 0 0 0
##
## caffer arundinum ellipsiprymnus fulvorufulva leche
## buselaphus 0 0 0 0 0
## dorcas 0 0 0 0 0
## gnou 0 0 0 0 0
## taurinus 0 0 0 0 0
## marsupialis 0 0 0 0 0
## oryx 0 0 0 0 0
## scriptus 0 0 0 0 0
## strepsiceros 0 0 0 0 0
## campestris 0 0 0 0 0
## capreolus 0 0 0 0 0
## oreotragus 0 0 0 0 0
## ourebi 0 0 0 0 0
## caffer 7 0 0 0 0
## arundinum 0 20 0 3 2
## ellipsiprymnus 0 8 9 1 6
## fulvorufulva 0 8 0 13 0
## leche 0 15 1 1 5
## equinus 0 3 2 0 4
## gazella 1 1 0 4 0
## niger 0 8 2 1 0
##
## equinus gazella niger
## buselaphus 0 0 0
## dorcas 0 0 0
## gnou 0 0 0
## taurinus 0 0 0
## marsupialis 0 0 0
## oryx 0 0 0
## scriptus 0 0 0
## strepsiceros 0 0 0
## campestris 0 0 0
## capreolus 0 0 0
## oreotragus 0 0 0
## ourebi 0 0 0
## caffer 0 0 0
## arundinum 0 0 0
## ellipsiprymnus 0 0 0
## fulvorufulva 0 0 0
## leche 0 0 0
## equinus 0 0 0
## gazella 0 0 1
## niger 0 0 0
Confusion matrix - No Imputation
#Predict the class
spec <- c("buselaphus","dorcas","gnou","taurinus", "marsupialis","oryx","scriptus","strepsiceros", "campestris","capreolus","oreotragus","ourebi","caffer", "arundinum","ellipsiprymnus","fulvorufulva","leche", "equinus","gazella","niger")
part_match_df$pred <- names(part_match_df[,1:20])[apply(part_match_df[,1:20],1,which.max)]
table(factor(part_match_df$true,levels = spec),factor(part_match_df$pred, levels = spec))
##
## buselaphus dorcas gnou taurinus marsupialis oryx scriptus
## buselaphus 5 12 7 5 2 0 0
## dorcas 0 30 1 0 0 0 0
## gnou 3 8 15 4 0 0 0
## taurinus 5 0 6 14 0 0 0
## marsupialis 0 2 0 0 26 0 2
## oryx 0 0 0 0 0 16 0
## scriptus 0 0 0 0 0 0 21
## strepsiceros 0 0 1 0 2 3 0
## campestris 0 0 2 0 0 0 0
## capreolus 0 0 0 0 0 0 6
## oreotragus 0 0 0 0 0 0 0
## ourebi 0 0 0 0 0 0 4
## caffer 0 0 2 2 0 1 0
## arundinum 0 0 0 0 0 0 0
## ellipsiprymnus 0 0 0 0 0 0 0
## fulvorufulva 0 2 0 0 0 0 1
## leche 0 0 0 0 0 0 0
## equinus 0 0 0 0 0 0 0
## gazella 1 0 0 1 0 1 0
## niger 0 0 0 0 0 0 0
##
## strepsiceros campestris capreolus oreotragus ourebi
## buselaphus 0 0 0 0 0
## dorcas 0 0 0 0 0
## gnou 0 0 0 0 0
## taurinus 0 0 0 0 0
## marsupialis 0 0 0 0 0
## oryx 4 0 0 0 0
## scriptus 0 1 0 0 0
## strepsiceros 14 0 0 0 0
## campestris 0 23 0 0 0
## capreolus 0 3 0 0 0
## oreotragus 0 12 0 0 0
## ourebi 0 5 0 0 0
## caffer 1 0 0 0 0
## arundinum 0 0 0 0 0
## ellipsiprymnus 0 0 0 0 0
## fulvorufulva 0 0 0 0 0
## leche 0 0 0 0 0
## equinus 0 0 0 0 0
## gazella 0 0 0 0 0
## niger 0 0 0 0 0
##
## caffer arundinum ellipsiprymnus fulvorufulva leche
## buselaphus 0 0 0 0 0
## dorcas 0 0 0 0 0
## gnou 0 0 0 0 0
## taurinus 0 0 0 0 0
## marsupialis 0 0 0 0 0
## oryx 0 0 0 0 0
## scriptus 0 0 0 0 0
## strepsiceros 0 0 0 0 0
## campestris 0 0 0 0 0
## capreolus 0 0 0 0 0
## oreotragus 0 0 0 0 0
## ourebi 0 0 0 0 0
## caffer 13 0 0 0 0
## arundinum 0 20 0 1 4
## ellipsiprymnus 0 2 18 0 6
## fulvorufulva 0 3 0 17 0
## leche 0 12 0 0 10
## equinus 0 0 10 0 1
## gazella 0 0 1 0 0
## niger 0 1 9 1 1
##
## equinus gazella niger
## buselaphus 0 0 0
## dorcas 0 0 0
## gnou 0 0 0
## taurinus 0 0 0
## marsupialis 0 0 0
## oryx 0 0 0
## scriptus 0 0 0
## strepsiceros 0 0 0
## campestris 0 1 0
## capreolus 0 0 0
## oreotragus 0 0 0
## ourebi 0 0 0
## caffer 0 0 0
## arundinum 0 0 0
## ellipsiprymnus 0 0 0
## fulvorufulva 0 0 0
## leche 0 0 0
## equinus 0 0 0
## gazella 0 1 4
## niger 0 0 2
Confusion matrix - Imputed Shapes
#Predict the class
imputed_match_df$pred <- names(imputed_match_df[,1:7])[apply(imputed_match_df[,1:7],1,which.max)]
table(factor(imputed_match_df$true,levels = c("Alcelaphini", "Antilopini", "Tragelaphini", "Neotragini","Bovini", "Reduncini", "Hippotragini" )),factor(imputed_match_df$pred, levels = c("Alcelaphini", "Antilopini", "Tragelaphini", "Neotragini","Bovini", "Reduncini", "Hippotragini" )))
##
## Alcelaphini Antilopini Tragelaphini Neotragini Bovini
## Alcelaphini 117 0 0 0 0
## Antilopini 0 26 3 1 0
## Tragelaphini 4 1 36 16 0
## Neotragini 0 1 3 49 0
## Bovini 2 0 2 0 7
## Reduncini 1 0 0 7 0
## Hippotragini 2 0 0 1 0
##
## Reduncini Hippotragini
## Alcelaphini 0 0
## Antilopini 0 0
## Tragelaphini 5 0
## Neotragini 3 0
## Bovini 8 0
## Reduncini 88 0
## Hippotragini 30 1
Confusion matrix - No Imputation
part_match_df$pred <- names(part_match_df[,1:7])[apply(part_match_df[,1:7],1,which.max)]
table(factor(part_match_df$true,levels = c("Alcelaphini", "Antilopini", "Tragelaphini", "Neotragini","Bovini", "Reduncini", "Hippotragini" )),factor(part_match_df$pred, levels = c("Alcelaphini", "Antilopini", "Tragelaphini", "Neotragini","Bovini", "Reduncini", "Hippotragini" )))
##
## Alcelaphini Antilopini Tragelaphini Neotragini Bovini
## Alcelaphini 115 1 0 0 0
## Antilopini 0 30 0 0 0
## Tragelaphini 2 0 53 5 0
## Neotragini 1 3 4 44 0
## Bovini 1 0 0 0 7
## Reduncini 1 0 0 0 0
## Hippotragini 2 0 0 0 0
##
## Reduncini Hippotragini
## Alcelaphini 0 1
## Antilopini 0 0
## Tragelaphini 2 0
## Neotragini 4 0
## Bovini 8 3
## Reduncini 91 4
## Hippotragini 17 15
ROC Analysis - One class at a time Imputed - Blue, No Imputation - Red
#ROC analysis
for (q in c("Alcelaphini","Antilopini","Bovini","Hippotragini","Neotragini","Reduncini","Tragelaphini")){
temp <- imputed_match_df
tribe <- q
temp$true <- as.character(temp$true)
temp$true[(temp$true) != tribe] <- 0
temp$true[(temp$true) == tribe] <- 1
library(ROCR)
pred <- prediction(temp[[tribe]], as.numeric(temp$true))
perf <- performance(pred, measure = "tpr", x.measure = "fpr")
plot(perf, col="blue", main = tribe)
temp <- part_match_df
temp$true <- as.character(temp$true)
temp$true[(temp$true) != tribe] <- 0
temp$true[(temp$true) == tribe] <- 1
library(ROCR)
pred <- prediction(temp[[tribe]], as.numeric(temp$true))
perf <- performance(pred, measure = "tpr", x.measure = "fpr")
plot(perf, col="red", add = TRUE, lty = 3)
}
Predicting Species
load("/Users/gregorymatthews/Dropbox/shapeanalysisgit/results/results20190610_side=2_k=5_M=5_tooth=LM3_summaries_species.RData")
fret <- data.frame(logloss = c(logloss_imputed,logloss_part), k = c(1:20,1:20), method = c(rep("knn w Imputation",20),rep("knn no imputation",20)))
library(ggplot2)
ggplot(aes(x = k, y = logloss, col = method), data = fret) + geom_point() + geom_line()
Confusion matrix - Imputed Shapes
#Predict the class
spec <- c("buselaphus","dorcas","gnou","taurinus", "marsupialis","oryx","scriptus","strepsiceros", "campestris","capreolus","oreotragus","ourebi","caffer", "arundinum","ellipsiprymnus","fulvorufulva","leche", "equinus","gazella","niger")
imputed_match_df$pred <- names(imputed_match_df[,1:20])[apply(imputed_match_df[,1:20],1,which.max)]
table(factor(imputed_match_df$true,levels = spec),factor(imputed_match_df$pred, levels = spec))
##
## buselaphus dorcas gnou taurinus marsupialis oryx scriptus
## buselaphus 11 3 16 0 1 0 0
## dorcas 0 28 3 0 0 0 0
## gnou 1 7 22 0 0 0 0
## taurinus 4 8 13 0 0 0 0
## marsupialis 0 0 0 0 27 0 3
## oryx 0 0 0 0 1 11 0
## scriptus 0 0 0 0 1 0 15
## strepsiceros 0 0 0 0 1 4 1
## campestris 0 0 0 0 0 1 0
## capreolus 0 0 0 0 3 0 3
## oreotragus 0 0 0 0 0 0 0
## ourebi 0 0 0 0 0 0 0
## caffer 0 1 0 0 0 0 0
## arundinum 0 0 0 0 0 0 0
## ellipsiprymnus 0 0 0 0 1 0 1
## fulvorufulva 0 0 0 0 0 0 0
## leche 0 0 0 0 0 0 0
## equinus 0 0 0 0 0 0 0
## gazella 1 0 0 0 0 0 0
## niger 1 0 1 0 0 0 0
##
## strepsiceros campestris capreolus oreotragus ourebi
## buselaphus 0 0 0 0 0
## dorcas 0 0 0 0 0
## gnou 0 0 0 0 0
## taurinus 0 0 0 0 0
## marsupialis 0 0 0 0 0
## oryx 7 0 0 0 0
## scriptus 0 2 0 2 0
## strepsiceros 10 0 0 0 0
## campestris 2 22 0 0 0
## capreolus 0 1 0 1 0
## oreotragus 0 11 0 1 0
## ourebi 0 3 0 4 0
## caffer 2 0 0 0 0
## arundinum 0 2 0 0 0
## ellipsiprymnus 0 0 0 0 0
## fulvorufulva 0 0 0 0 0
## leche 0 1 0 0 0
## equinus 0 1 0 0 0
## gazella 0 0 0 0 0
## niger 0 0 0 0 0
##
## caffer arundinum ellipsiprymnus fulvorufulva leche
## buselaphus 0 0 0 0 0
## dorcas 0 0 0 0 0
## gnou 0 0 0 0 0
## taurinus 0 0 0 0 0
## marsupialis 0 0 0 0 0
## oryx 1 0 0 0 0
## scriptus 0 1 0 1 0
## strepsiceros 0 0 1 2 0
## campestris 0 1 0 0 0
## capreolus 0 0 0 1 0
## oreotragus 0 0 0 0 0
## ourebi 0 0 0 2 0
## caffer 11 2 0 3 0
## arundinum 0 13 0 9 1
## ellipsiprymnus 0 14 3 4 1
## fulvorufulva 0 6 0 17 0
## leche 0 15 0 6 0
## equinus 0 3 0 5 0
## gazella 0 1 0 6 0
## niger 0 7 1 4 0
##
## equinus gazella niger
## buselaphus 0 0 0
## dorcas 0 0 0
## gnou 0 0 0
## taurinus 0 0 0
## marsupialis 0 0 0
## oryx 0 0 0
## scriptus 0 0 0
## strepsiceros 0 0 1
## campestris 0 0 0
## capreolus 0 0 0
## oreotragus 0 0 0
## ourebi 0 0 0
## caffer 0 0 0
## arundinum 0 0 0
## ellipsiprymnus 0 0 2
## fulvorufulva 0 0 0
## leche 0 0 0
## equinus 0 0 2
## gazella 0 0 1
## niger 0 0 0
Confusion matrix - No Imputation
#Predict the class
spec <- c("buselaphus","dorcas","gnou","taurinus", "marsupialis","oryx","scriptus","strepsiceros", "campestris","capreolus","oreotragus","ourebi","caffer", "arundinum","ellipsiprymnus","fulvorufulva","leche", "equinus","gazella","niger")
part_match_df$pred <- names(part_match_df[,1:20])[apply(part_match_df[,1:20],1,which.max)]
table(factor(part_match_df$true,levels = spec),factor(part_match_df$pred, levels = spec))
##
## buselaphus dorcas gnou taurinus marsupialis oryx scriptus
## buselaphus 18 4 5 1 2 0 0
## dorcas 1 28 1 0 1 0 0
## gnou 2 3 24 1 0 0 0
## taurinus 3 0 12 9 0 0 0
## marsupialis 0 0 0 0 30 0 0
## oryx 0 0 0 0 0 17 0
## scriptus 0 0 0 0 0 0 19
## strepsiceros 1 0 0 0 1 3 0
## campestris 0 1 0 0 1 3 0
## capreolus 0 0 0 0 5 0 2
## oreotragus 0 0 0 0 0 0 0
## ourebi 0 0 0 0 0 0 1
## caffer 0 0 0 0 0 0 0
## arundinum 0 0 0 0 0 0 0
## ellipsiprymnus 0 0 0 0 1 0 0
## fulvorufulva 0 0 0 0 0 0 0
## leche 0 0 0 0 0 0 0
## equinus 0 0 0 0 0 0 0
## gazella 1 0 0 0 0 0 0
## niger 1 0 0 0 0 0 0
##
## strepsiceros campestris capreolus oreotragus ourebi
## buselaphus 0 0 0 0 0
## dorcas 0 0 0 0 0
## gnou 0 0 0 0 0
## taurinus 0 0 0 0 0
## marsupialis 0 0 0 0 0
## oryx 3 0 0 0 0
## scriptus 0 3 0 0 0
## strepsiceros 12 0 0 0 0
## campestris 0 21 0 0 0
## capreolus 0 0 0 2 0
## oreotragus 0 11 0 1 0
## ourebi 0 5 0 0 0
## caffer 0 0 0 0 0
## arundinum 0 0 0 0 0
## ellipsiprymnus 0 0 0 0 0
## fulvorufulva 0 0 0 0 0
## leche 0 0 0 0 0
## equinus 0 0 0 0 0
## gazella 0 0 0 0 0
## niger 0 0 0 0 0
##
## caffer arundinum ellipsiprymnus fulvorufulva leche
## buselaphus 0 0 1 0 0
## dorcas 0 0 0 0 0
## gnou 0 0 0 0 0
## taurinus 0 0 1 0 0
## marsupialis 0 0 0 0 0
## oryx 0 0 0 0 0
## scriptus 0 0 0 0 0
## strepsiceros 0 0 3 0 0
## campestris 0 0 0 0 0
## capreolus 0 0 0 0 0
## oreotragus 0 0 0 0 0
## ourebi 0 0 0 3 0
## caffer 10 1 8 0 0
## arundinum 0 13 0 9 3
## ellipsiprymnus 0 0 23 0 1
## fulvorufulva 0 7 1 14 1
## leche 0 7 1 3 11
## equinus 0 0 8 0 2
## gazella 0 0 8 0 0
## niger 0 1 10 0 1
##
## equinus gazella niger
## buselaphus 0 0 0
## dorcas 0 0 0
## gnou 0 0 0
## taurinus 0 0 0
## marsupialis 0 0 0
## oryx 0 0 0
## scriptus 0 0 0
## strepsiceros 0 0 0
## campestris 0 0 0
## capreolus 0 0 0
## oreotragus 0 0 0
## ourebi 0 0 0
## caffer 0 0 0
## arundinum 0 0 0
## ellipsiprymnus 0 0 1
## fulvorufulva 0 0 0
## leche 0 0 0
## equinus 0 0 1
## gazella 0 0 0
## niger 0 0 1
Confusion matrix - Imputed Shapes
#Predict the class
imputed_match_df$pred <- names(imputed_match_df[,1:7])[apply(imputed_match_df[,1:7],1,which.max)]
table(factor(imputed_match_df$true,levels = c("Alcelaphini", "Antilopini", "Tragelaphini", "Neotragini","Bovini", "Reduncini", "Hippotragini" )),factor(imputed_match_df$pred, levels = c("Alcelaphini", "Antilopini", "Tragelaphini", "Neotragini","Bovini", "Reduncini", "Hippotragini" )))
##
## Alcelaphini Antilopini Tragelaphini Neotragini Bovini
## Alcelaphini 114 1 1 1 0
## Antilopini 0 18 10 2 0
## Tragelaphini 0 3 80 11 0
## Neotragini 0 2 2 49 0
## Bovini 6 0 5 0 0
## Reduncini 7 3 12 6 0
## Hippotragini 4 0 3 3 0
##
## Reduncini Hippotragini
## Alcelaphini 2 0
## Antilopini 0 0
## Tragelaphini 0 0
## Neotragini 0 0
## Bovini 6 7
## Reduncini 68 2
## Hippotragini 10 22
Confusion matrix - No Imputation
part_match_df$pred <- names(part_match_df[,1:7])[apply(part_match_df[,1:7],1,which.max)]
table(factor(part_match_df$true,levels = c("Alcelaphini", "Antilopini", "Tragelaphini", "Neotragini","Bovini", "Reduncini", "Hippotragini" )),factor(part_match_df$pred, levels = c("Alcelaphini", "Antilopini", "Tragelaphini", "Neotragini","Bovini", "Reduncini", "Hippotragini" )))
##
## Alcelaphini Antilopini Tragelaphini Neotragini Bovini
## Alcelaphini 116 2 0 0 0
## Antilopini 0 28 0 2 0
## Tragelaphini 0 1 88 5 0
## Neotragini 0 3 2 48 0
## Bovini 10 0 0 0 9
## Reduncini 8 1 5 3 1
## Hippotragini 5 0 3 0 0
##
## Reduncini Hippotragini
## Alcelaphini 1 0
## Antilopini 0 0
## Tragelaphini 0 0
## Neotragini 0 0
## Bovini 2 3
## Reduncini 78 2
## Hippotragini 11 23
ROC Analysis - One class at a time Imputed - Blue, No Imputation - Red
#ROC analysis
for (q in c("Alcelaphini","Antilopini","Bovini","Hippotragini","Neotragini","Reduncini","Tragelaphini")){
temp <- imputed_match_df
tribe <- q
temp$true <- as.character(temp$true)
temp$true[(temp$true) != tribe] <- 0
temp$true[(temp$true) == tribe] <- 1
library(ROCR)
pred <- prediction(temp[[tribe]], as.numeric(temp$true))
perf <- performance(pred, measure = "tpr", x.measure = "fpr")
plot(perf, col="blue", main = tribe)
temp <- part_match_df
temp$true <- as.character(temp$true)
temp$true[(temp$true) != tribe] <- 0
temp$true[(temp$true) == tribe] <- 1
library(ROCR)
pred <- prediction(temp[[tribe]], as.numeric(temp$true))
perf <- performance(pred, measure = "tpr", x.measure = "fpr")
plot(perf, col="red", add = TRUE, lty = 3)
}
Predicting Species
load("/Users/gregorymatthews/Dropbox/shapeanalysisgit/results/results20190610_side=1_k=5_M=5_tooth=UM2_summaries_species.RData")
fret <- data.frame(logloss = c(logloss_imputed,logloss_part), k = c(1:20,1:20), method = c(rep("knn w Imputation",20),rep("knn no imputation",20)))
library(ggplot2)
ggplot(aes(x = k, y = logloss, col = method), data = fret) + geom_point() + geom_line()
Confusion matrix - Imputed Shapes
#Predict the class
spec <- c("buselaphus","dorcas","gnou","taurinus", "marsupialis","oryx","scriptus","strepsiceros", "campestris","capreolus","oreotragus","ourebi","caffer", "arundinum","ellipsiprymnus","fulvorufulva","leche", "equinus","gazella","niger")
imputed_match_df$pred <- names(imputed_match_df[,1:20])[apply(imputed_match_df[,1:20],1,which.max)]
table(factor(imputed_match_df$true,levels = spec),factor(imputed_match_df$pred, levels = spec))
##
## buselaphus dorcas gnou taurinus marsupialis oryx scriptus
## buselaphus 12 11 3 1 0 0 0
## dorcas 3 25 2 0 0 0 0
## gnou 1 1 18 4 0 0 0
## taurinus 2 1 5 18 1 0 1
## marsupialis 0 0 0 0 20 0 8
## oryx 0 0 0 0 0 0 0
## scriptus 0 0 0 0 4 0 23
## strepsiceros 0 0 0 0 0 0 1
## campestris 0 0 0 0 0 0 0
## capreolus 0 0 0 0 2 0 5
## oreotragus 0 0 0 0 0 0 0
## ourebi 0 0 0 0 0 0 1
## caffer 0 0 1 2 0 0 0
## arundinum 0 0 0 0 1 0 1
## ellipsiprymnus 2 0 0 3 0 0 0
## fulvorufulva 0 0 0 0 0 0 0
## leche 0 1 0 0 5 0 2
## equinus 0 0 0 0 0 0 0
## gazella 1 0 1 0 0 0 0
## niger 0 0 1 0 0 0 0
##
## strepsiceros campestris capreolus oreotragus ourebi
## buselaphus 2 1 0 0 0
## dorcas 0 0 0 0 0
## gnou 2 0 0 0 0
## taurinus 3 0 0 0 0
## marsupialis 2 0 0 0 0
## oryx 31 0 0 0 0
## scriptus 0 5 0 0 0
## strepsiceros 30 0 0 0 0
## campestris 0 24 0 0 0
## capreolus 0 1 0 0 0
## oreotragus 0 13 0 0 0
## ourebi 0 6 0 1 0
## caffer 7 0 0 0 0
## arundinum 0 2 0 0 0
## ellipsiprymnus 8 1 0 0 0
## fulvorufulva 1 0 0 0 1
## leche 2 0 0 0 0
## equinus 1 0 0 0 0
## gazella 2 0 0 0 0
## niger 3 0 0 1 0
##
## caffer arundinum ellipsiprymnus fulvorufulva leche
## buselaphus 0 0 0 0 0
## dorcas 0 0 0 0 0
## gnou 0 0 0 2 0
## taurinus 0 0 0 0 0
## marsupialis 0 0 0 0 0
## oryx 0 0 0 0 0
## scriptus 0 0 0 0 0
## strepsiceros 0 0 0 0 0
## campestris 0 0 0 0 0
## capreolus 0 0 0 0 0
## oreotragus 0 0 0 0 0
## ourebi 0 0 0 0 0
## caffer 0 5 0 1 1
## arundinum 0 17 0 5 1
## ellipsiprymnus 0 2 1 2 1
## fulvorufulva 0 5 0 18 0
## leche 1 5 0 6 2
## equinus 0 0 0 1 0
## gazella 0 5 0 1 0
## niger 0 0 0 1 1
##
## equinus gazella niger
## buselaphus 0 0 0
## dorcas 0 0 0
## gnou 0 0 0
## taurinus 0 0 0
## marsupialis 0 0 0
## oryx 0 0 0
## scriptus 0 0 0
## strepsiceros 0 0 0
## campestris 0 0 0
## capreolus 0 0 0
## oreotragus 0 0 0
## ourebi 0 0 0
## caffer 0 0 7
## arundinum 0 0 1
## ellipsiprymnus 0 0 1
## fulvorufulva 0 0 0
## leche 0 0 0
## equinus 0 0 9
## gazella 0 0 1
## niger 1 0 12
Confusion matrix - No Imputation
#Predict the class
spec <- c("buselaphus","dorcas","gnou","taurinus", "marsupialis","oryx","scriptus","strepsiceros", "campestris","capreolus","oreotragus","ourebi","caffer", "arundinum","ellipsiprymnus","fulvorufulva","leche", "equinus","gazella","niger")
part_match_df$pred <- names(part_match_df[,1:20])[apply(part_match_df[,1:20],1,which.max)]
table(factor(part_match_df$true,levels = spec),factor(part_match_df$pred, levels = spec))
##
## buselaphus dorcas gnou taurinus marsupialis oryx scriptus
## buselaphus 13 12 2 2 1 0 0
## dorcas 2 28 0 0 0 0 0
## gnou 1 1 16 8 0 0 0
## taurinus 1 0 5 23 1 0 0
## marsupialis 0 0 0 0 30 0 0
## oryx 0 0 0 0 0 9 0
## scriptus 0 0 0 0 3 0 27
## strepsiceros 0 0 0 0 0 1 0
## campestris 0 0 0 0 0 0 0
## capreolus 0 0 0 0 4 0 2
## oreotragus 0 0 0 0 0 0 0
## ourebi 0 0 0 0 0 0 0
## caffer 0 0 0 8 0 0 0
## arundinum 0 0 0 0 1 0 1
## ellipsiprymnus 6 0 1 0 0 0 0
## fulvorufulva 0 0 0 0 0 0 0
## leche 0 0 0 1 2 0 1
## equinus 0 0 0 0 0 0 0
## gazella 1 0 0 0 0 0 0
## niger 0 0 2 0 0 0 0
##
## strepsiceros campestris capreolus oreotragus ourebi
## buselaphus 0 0 0 0 0
## dorcas 0 0 0 0 0
## gnou 1 0 0 0 0
## taurinus 0 0 0 0 0
## marsupialis 0 0 0 0 0
## oryx 22 0 0 0 0
## scriptus 0 2 0 0 0
## strepsiceros 30 0 0 0 0
## campestris 0 24 0 0 0
## capreolus 0 1 0 1 0
## oreotragus 0 8 0 5 0
## ourebi 0 8 0 0 0
## caffer 1 0 0 0 0
## arundinum 0 1 1 0 0
## ellipsiprymnus 2 0 0 0 0
## fulvorufulva 0 0 0 0 0
## leche 2 0 0 0 0
## equinus 0 0 0 0 0
## gazella 3 0 0 0 0
## niger 0 0 0 0 0
##
## caffer arundinum ellipsiprymnus fulvorufulva leche
## buselaphus 0 0 0 0 0
## dorcas 0 0 0 0 0
## gnou 0 0 0 1 0
## taurinus 1 0 0 0 0
## marsupialis 0 0 0 0 0
## oryx 0 0 0 0 0
## scriptus 0 0 0 0 0
## strepsiceros 0 0 0 0 0
## campestris 0 0 0 0 0
## capreolus 0 0 0 0 0
## oreotragus 0 0 0 0 0
## ourebi 0 0 0 0 0
## caffer 13 0 1 0 0
## arundinum 0 17 0 6 1
## ellipsiprymnus 0 3 5 3 0
## fulvorufulva 0 5 1 19 0
## leche 1 3 4 5 5
## equinus 0 0 2 0 0
## gazella 1 6 0 0 0
## niger 0 2 0 0 2
##
## equinus gazella niger
## buselaphus 0 0 0
## dorcas 0 0 0
## gnou 0 0 0
## taurinus 0 0 0
## marsupialis 0 0 0
## oryx 0 0 0
## scriptus 0 0 0
## strepsiceros 0 0 0
## campestris 0 0 0
## capreolus 0 0 0
## oreotragus 0 0 0
## ourebi 0 0 0
## caffer 0 0 1
## arundinum 0 0 0
## ellipsiprymnus 0 0 1
## fulvorufulva 0 0 0
## leche 0 0 0
## equinus 0 0 9
## gazella 0 0 0
## niger 0 0 14
Confusion matrix - Imputed Shapes
#Predict the class
imputed_match_df$pred <- names(imputed_match_df[,1:7])[apply(imputed_match_df[,1:7],1,which.max)]
table(factor(imputed_match_df$true,levels = c("Alcelaphini", "Antilopini", "Tragelaphini", "Neotragini","Bovini", "Reduncini", "Hippotragini" )),factor(imputed_match_df$pred, levels = c("Alcelaphini", "Antilopini", "Tragelaphini", "Neotragini","Bovini", "Reduncini", "Hippotragini" )))
##
## Alcelaphini Antilopini Tragelaphini Neotragini Bovini
## Alcelaphini 109 0 7 1 0
## Antilopini 0 19 4 6 0
## Tragelaphini 0 1 87 6 0
## Neotragini 0 0 6 47 0
## Bovini 5 0 8 0 0
## Reduncini 4 0 10 3 0
## Hippotragini 8 0 6 0 0
##
## Reduncini Hippotragini
## Alcelaphini 2 0
## Antilopini 1 0
## Tragelaphini 0 0
## Neotragini 0 0
## Bovini 8 3
## Reduncini 79 2
## Hippotragini 9 19
Confusion matrix - No Imputation
part_match_df$pred <- names(part_match_df[,1:7])[apply(part_match_df[,1:7],1,which.max)]
table(factor(part_match_df$true,levels = c("Alcelaphini", "Antilopini", "Tragelaphini", "Neotragini","Bovini", "Reduncini", "Hippotragini" )),factor(part_match_df$pred, levels = c("Alcelaphini", "Antilopini", "Tragelaphini", "Neotragini","Bovini", "Reduncini", "Hippotragini" )))
##
## Alcelaphini Antilopini Tragelaphini Neotragini Bovini
## Alcelaphini 101 0 16 0 0
## Antilopini 0 21 7 1 0
## Tragelaphini 0 0 92 1 0
## Neotragini 0 2 8 41 0
## Bovini 4 0 7 0 8
## Reduncini 4 0 10 0 0
## Hippotragini 6 0 3 0 0
##
## Reduncini Hippotragini
## Alcelaphini 2 0
## Antilopini 1 0
## Tragelaphini 1 0
## Neotragini 2 0
## Bovini 0 5
## Reduncini 77 7
## Hippotragini 1 32
ROC Analysis - One class at a time Imputed - Blue, No Imputation - Red
#ROC analysis
for (q in c("Alcelaphini","Antilopini","Bovini","Hippotragini","Neotragini","Reduncini","Tragelaphini")){
temp <- imputed_match_df
tribe <- q
temp$true <- as.character(temp$true)
temp$true[(temp$true) != tribe] <- 0
temp$true[(temp$true) == tribe] <- 1
library(ROCR)
pred <- prediction(temp[[tribe]], as.numeric(temp$true))
perf <- performance(pred, measure = "tpr", x.measure = "fpr")
plot(perf, col="blue", main = tribe)
temp <- part_match_df
temp$true <- as.character(temp$true)
temp$true[(temp$true) != tribe] <- 0
temp$true[(temp$true) == tribe] <- 1
library(ROCR)
pred <- prediction(temp[[tribe]], as.numeric(temp$true))
perf <- performance(pred, measure = "tpr", x.measure = "fpr")
plot(perf, col="red", add = TRUE, lty = 3)
}
Predicting Species
load("/Users/gregorymatthews/Dropbox/shapeanalysisgit/results/results20190610_side=2_k=5_M=5_tooth=UM2_summaries_species.RData")
fret <- data.frame(logloss = c(logloss_imputed,logloss_part), k = c(1:20,1:20), method = c(rep("knn w Imputation",20),rep("knn no imputation",20)))
library(ggplot2)
ggplot(aes(x = k, y = logloss, col = method), data = fret) + geom_point() + geom_line()
Confusion matrix - Imputed Shapes
#Predict the class
spec <- c("buselaphus","dorcas","gnou","taurinus", "marsupialis","oryx","scriptus","strepsiceros", "campestris","capreolus","oreotragus","ourebi","caffer", "arundinum","ellipsiprymnus","fulvorufulva","leche", "equinus","gazella","niger")
imputed_match_df$pred <- names(imputed_match_df[,1:20])[apply(imputed_match_df[,1:20],1,which.max)]
table(factor(imputed_match_df$true,levels = spec),factor(imputed_match_df$pred, levels = spec))
##
## buselaphus dorcas gnou taurinus marsupialis oryx scriptus
## buselaphus 15 4 0 1 1 0 0
## dorcas 6 23 0 0 0 0 0
## gnou 3 0 19 1 0 0 0
## taurinus 2 0 7 10 0 0 0
## marsupialis 0 0 0 0 22 0 3
## oryx 0 0 0 0 0 0 0
## scriptus 0 0 0 0 1 0 29
## strepsiceros 0 0 0 0 0 0 0
## campestris 0 0 0 0 0 0 0
## capreolus 0 0 0 0 0 0 8
## oreotragus 0 0 0 0 0 0 0
## ourebi 0 0 0 0 0 0 3
## caffer 0 0 2 0 0 0 0
## arundinum 0 0 0 0 0 0 4
## ellipsiprymnus 0 0 1 0 1 0 0
## fulvorufulva 0 0 0 1 0 0 0
## leche 0 0 0 0 0 0 3
## equinus 1 0 0 0 0 0 0
## gazella 0 0 4 0 0 0 0
## niger 1 0 0 0 0 0 0
##
## strepsiceros campestris capreolus oreotragus ourebi
## buselaphus 7 0 0 0 0
## dorcas 1 0 0 0 0
## gnou 5 0 0 0 0
## taurinus 12 0 0 0 0
## marsupialis 1 3 0 0 0
## oryx 31 0 0 0 0
## scriptus 0 2 0 0 0
## strepsiceros 31 0 0 0 0
## campestris 0 24 0 0 0
## capreolus 0 0 0 0 0
## oreotragus 0 13 0 0 0
## ourebi 0 4 0 0 0
## caffer 11 0 0 0 0
## arundinum 0 1 0 0 0
## ellipsiprymnus 7 1 0 0 0
## fulvorufulva 0 0 0 0 0
## leche 8 0 0 0 0
## equinus 2 0 0 0 0
## gazella 4 0 0 0 0
## niger 5 0 0 0 0
##
## caffer arundinum ellipsiprymnus fulvorufulva leche
## buselaphus 0 0 0 2 0
## dorcas 0 0 0 0 0
## gnou 0 0 0 0 0
## taurinus 0 0 0 0 0
## marsupialis 0 0 0 0 1
## oryx 0 0 0 0 0
## scriptus 0 0 0 0 0
## strepsiceros 0 0 0 0 0
## campestris 0 0 0 0 0
## capreolus 0 0 0 0 0
## oreotragus 0 0 0 0 0
## ourebi 0 1 0 0 0
## caffer 2 5 0 0 0
## arundinum 0 10 0 12 1
## ellipsiprymnus 0 4 1 3 0
## fulvorufulva 0 0 0 24 0
## leche 0 1 0 11 1
## equinus 0 2 0 1 0
## gazella 0 0 0 0 0
## niger 0 2 0 0 3
##
## equinus gazella niger
## buselaphus 0 0 0
## dorcas 0 0 0
## gnou 0 0 0
## taurinus 0 0 0
## marsupialis 0 0 0
## oryx 0 0 0
## scriptus 0 0 0
## strepsiceros 0 0 0
## campestris 0 0 0
## capreolus 0 0 0
## oreotragus 0 0 0
## ourebi 0 0 0
## caffer 0 0 4
## arundinum 0 0 0
## ellipsiprymnus 0 0 3
## fulvorufulva 0 0 0
## leche 0 0 0
## equinus 0 0 5
## gazella 0 0 3
## niger 0 0 9
Confusion matrix - No Imputation
#Predict the class
spec <- c("buselaphus","dorcas","gnou","taurinus", "marsupialis","oryx","scriptus","strepsiceros", "campestris","capreolus","oreotragus","ourebi","caffer", "arundinum","ellipsiprymnus","fulvorufulva","leche", "equinus","gazella","niger")
part_match_df$pred <- names(part_match_df[,1:20])[apply(part_match_df[,1:20],1,which.max)]
table(factor(part_match_df$true,levels = spec),factor(part_match_df$pred, levels = spec))
##
## buselaphus dorcas gnou taurinus marsupialis oryx scriptus
## buselaphus 19 6 1 2 0 0 0
## dorcas 0 30 0 0 0 0 0
## gnou 1 0 17 1 0 0 0
## taurinus 2 0 3 15 0 0 0
## marsupialis 0 0 0 0 22 0 3
## oryx 0 0 0 0 0 2 0
## scriptus 0 0 0 0 0 0 30
## strepsiceros 0 0 0 0 0 1 0
## campestris 0 0 0 0 0 0 0
## capreolus 0 0 0 0 2 0 6
## oreotragus 0 0 0 0 0 0 0
## ourebi 0 0 0 0 0 0 6
## caffer 0 0 2 1 0 0 0
## arundinum 0 0 0 0 0 0 1
## ellipsiprymnus 0 0 0 0 0 0 0
## fulvorufulva 0 0 0 0 0 0 0
## leche 0 0 1 0 0 1 1
## equinus 0 0 0 0 0 0 0
## gazella 0 0 4 1 0 0 0
## niger 0 0 0 0 0 0 0
##
## strepsiceros campestris capreolus oreotragus ourebi
## buselaphus 1 0 0 0 0
## dorcas 0 0 0 0 0
## gnou 9 0 0 0 0
## taurinus 11 0 0 0 0
## marsupialis 4 0 0 0 0
## oryx 29 0 0 0 0
## scriptus 0 0 0 1 0
## strepsiceros 30 0 0 0 0
## campestris 0 24 0 0 0
## capreolus 0 0 0 0 0
## oreotragus 0 12 0 1 0
## ourebi 0 1 0 0 0
## caffer 7 0 0 0 0
## arundinum 0 0 0 0 0
## ellipsiprymnus 4 0 0 0 0
## fulvorufulva 1 0 0 0 0
## leche 3 0 0 0 0
## equinus 0 0 0 0 0
## gazella 2 0 0 0 0
## niger 2 0 0 0 0
##
## caffer arundinum ellipsiprymnus fulvorufulva leche
## buselaphus 0 0 0 1 0
## dorcas 0 0 0 0 0
## gnou 0 0 0 0 0
## taurinus 0 0 0 0 0
## marsupialis 0 1 0 0 0
## oryx 0 0 0 0 0
## scriptus 0 1 0 0 0
## strepsiceros 0 0 0 0 0
## campestris 0 0 0 0 0
## capreolus 0 0 0 0 0
## oreotragus 0 0 0 0 0
## ourebi 0 0 0 1 0
## caffer 11 0 1 0 0
## arundinum 0 23 0 4 0
## ellipsiprymnus 0 1 11 0 1
## fulvorufulva 0 3 1 20 0
## leche 0 3 1 0 13
## equinus 1 0 1 0 0
## gazella 0 0 2 0 0
## niger 0 0 1 0 0
##
## equinus gazella niger
## buselaphus 0 0 0
## dorcas 0 0 0
## gnou 0 0 0
## taurinus 0 0 0
## marsupialis 0 0 0
## oryx 0 0 0
## scriptus 0 0 0
## strepsiceros 0 0 0
## campestris 0 0 0
## capreolus 0 0 0
## oreotragus 0 0 0
## ourebi 0 0 0
## caffer 0 1 1
## arundinum 0 0 0
## ellipsiprymnus 0 0 4
## fulvorufulva 0 0 0
## leche 0 0 1
## equinus 3 0 6
## gazella 0 0 2
## niger 0 0 17
Confusion matrix - Imputed Shapes
#Predict the class
imputed_match_df$pred <- names(imputed_match_df[,1:7])[apply(imputed_match_df[,1:7],1,which.max)]
table(factor(imputed_match_df$true,levels = c("Alcelaphini", "Antilopini", "Tragelaphini", "Neotragini","Bovini", "Reduncini", "Hippotragini" )),factor(imputed_match_df$pred, levels = c("Alcelaphini", "Antilopini", "Tragelaphini", "Neotragini","Bovini", "Reduncini", "Hippotragini" )))
##
## Alcelaphini Antilopini Tragelaphini Neotragini Bovini
## Alcelaphini 48 1 1 6 0
## Antilopini 0 17 0 11 0
## Tragelaphini 2 2 53 12 0
## Neotragini 0 0 2 45 0
## Bovini 1 0 2 0 0
## Reduncini 6 1 2 7 0
## Hippotragini 5 1 1 0 0
##
## Reduncini Hippotragini
## Alcelaphini 10 5
## Antilopini 2 0
## Tragelaphini 6 3
## Neotragini 5 0
## Bovini 6 8
## Reduncini 88 6
## Hippotragini 27 24
Confusion matrix - No Imputation
part_match_df$pred <- names(part_match_df[,1:7])[apply(part_match_df[,1:7],1,which.max)]
table(factor(part_match_df$true,levels = c("Alcelaphini", "Antilopini", "Tragelaphini", "Neotragini","Bovini", "Reduncini", "Hippotragini" )),factor(part_match_df$pred, levels = c("Alcelaphini", "Antilopini", "Tragelaphini", "Neotragini","Bovini", "Reduncini", "Hippotragini" )))
##
## Alcelaphini Antilopini Tragelaphini Neotragini Bovini
## Alcelaphini 52 0 2 0 0
## Antilopini 0 25 1 1 0
## Tragelaphini 1 2 55 3 0
## Neotragini 0 0 7 43 0
## Bovini 0 0 0 0 8
## Reduncini 0 0 0 0 0
## Hippotragini 3 1 0 0 0
##
## Reduncini Hippotragini
## Alcelaphini 12 5
## Antilopini 3 0
## Tragelaphini 10 7
## Neotragini 2 0
## Bovini 0 9
## Reduncini 101 9
## Hippotragini 5 49
ROC Analysis - One class at a time Imputed - Blue, No Imputation - Red
#ROC analysis
for (q in c("Alcelaphini","Antilopini","Bovini","Hippotragini","Neotragini","Reduncini","Tragelaphini")){
temp <- imputed_match_df
tribe <- q
temp$true <- as.character(temp$true)
temp$true[(temp$true) != tribe] <- 0
temp$true[(temp$true) == tribe] <- 1
library(ROCR)
pred <- prediction(temp[[tribe]], as.numeric(temp$true))
perf <- performance(pred, measure = "tpr", x.measure = "fpr")
plot(perf, col="blue", main = tribe)
temp <- part_match_df
temp$true <- as.character(temp$true)
temp$true[(temp$true) != tribe] <- 0
temp$true[(temp$true) == tribe] <- 1
library(ROCR)
pred <- prediction(temp[[tribe]], as.numeric(temp$true))
perf <- performance(pred, measure = "tpr", x.measure = "fpr")
plot(perf, col="red", add = TRUE, lty = 3)
}
Predicting Species
load("/Users/gregorymatthews/Dropbox/shapeanalysisgit/results/results20190610_side=2_k=5_M=5_tooth=UM3_summaries_species.RData")
fret <- data.frame(logloss = c(logloss_imputed,logloss_part), k = c(1:20,1:20), method = c(rep("knn w Imputation",20),rep("knn no imputation",20)))
library(ggplot2)
ggplot(aes(x = k, y = logloss, col = method), data = fret) + geom_point() + geom_line()
Confusion matrix - Imputed Shapes
#Predict the class
spec <- c("buselaphus","dorcas","gnou","taurinus", "marsupialis","oryx","scriptus","strepsiceros", "campestris","capreolus","oreotragus","ourebi","caffer", "arundinum","ellipsiprymnus","fulvorufulva","leche", "equinus","gazella","niger")
imputed_match_df$pred <- names(imputed_match_df[,1:20])[apply(imputed_match_df[,1:20],1,which.max)]
table(factor(imputed_match_df$true,levels = spec),factor(imputed_match_df$pred, levels = spec))
##
## buselaphus dorcas gnou taurinus marsupialis oryx scriptus
## buselaphus 1 3 2 2 1 0 1
## dorcas 3 4 2 0 2 0 2
## gnou 3 0 4 3 2 0 1
## taurinus 0 2 2 8 0 0 0
## marsupialis 0 0 0 0 22 0 1
## oryx 0 0 0 1 8 9 0
## scriptus 0 0 0 0 0 0 17
## strepsiceros 0 0 1 0 3 7 0
## campestris 0 0 0 0 0 0 0
## capreolus 0 0 0 0 1 0 6
## oreotragus 0 0 0 0 0 0 0
## ourebi 0 0 0 0 0 0 0
## caffer 0 0 0 2 0 0 0
## arundinum 0 0 0 0 0 0 3
## ellipsiprymnus 0 0 1 5 1 0 2
## fulvorufulva 0 0 1 0 0 0 3
## leche 0 0 0 0 0 0 7
## equinus 0 0 1 1 0 0 0
## gazella 0 0 0 2 1 0 0
## niger 0 0 0 2 1 0 2
##
## strepsiceros campestris capreolus oreotragus ourebi
## buselaphus 0 0 0 0 0
## dorcas 0 1 0 0 0
## gnou 0 0 0 0 0
## taurinus 0 3 0 1 0
## marsupialis 0 5 0 1 0
## oryx 9 0 0 0 0
## scriptus 0 5 2 0 0
## strepsiceros 8 0 0 0 0
## campestris 0 23 0 0 0
## capreolus 0 2 0 0 0
## oreotragus 0 12 0 0 0
## ourebi 0 3 0 3 0
## caffer 1 0 0 0 0
## arundinum 0 0 0 0 0
## ellipsiprymnus 0 0 0 0 0
## fulvorufulva 0 1 0 0 0
## leche 0 0 0 1 0
## equinus 0 0 0 0 0
## gazella 0 0 0 0 0
## niger 0 0 0 0 0
##
## caffer arundinum ellipsiprymnus fulvorufulva leche
## buselaphus 0 0 1 0 1
## dorcas 0 0 0 1 0
## gnou 0 0 1 1 0
## taurinus 0 0 3 0 0
## marsupialis 0 0 0 0 1
## oryx 0 0 0 0 0
## scriptus 0 0 0 0 1
## strepsiceros 0 0 3 0 0
## campestris 0 0 0 0 0
## capreolus 0 0 0 1 0
## oreotragus 0 0 0 0 0
## ourebi 0 0 0 1 0
## caffer 1 1 2 0 0
## arundinum 0 9 0 15 1
## ellipsiprymnus 0 1 8 1 2
## fulvorufulva 0 1 0 22 1
## leche 0 3 0 5 7
## equinus 0 0 0 0 1
## gazella 0 0 7 1 1
## niger 0 0 5 0 4
##
## equinus gazella niger
## buselaphus 0 0 3
## dorcas 0 0 1
## gnou 0 0 0
## taurinus 0 1 5
## marsupialis 0 0 0
## oryx 0 0 2
## scriptus 0 0 0
## strepsiceros 0 0 2
## campestris 0 0 0
## capreolus 0 0 0
## oreotragus 0 0 0
## ourebi 0 0 0
## caffer 0 0 10
## arundinum 0 0 2
## ellipsiprymnus 0 0 6
## fulvorufulva 0 0 0
## leche 0 0 1
## equinus 0 0 11
## gazella 0 0 3
## niger 0 0 15
Confusion matrix - No Imputation
#Predict the class
spec <- c("buselaphus","dorcas","gnou","taurinus", "marsupialis","oryx","scriptus","strepsiceros", "campestris","capreolus","oreotragus","ourebi","caffer", "arundinum","ellipsiprymnus","fulvorufulva","leche", "equinus","gazella","niger")
part_match_df$pred <- names(part_match_df[,1:20])[apply(part_match_df[,1:20],1,which.max)]
table(factor(part_match_df$true,levels = spec),factor(part_match_df$pred, levels = spec))
##
## buselaphus dorcas gnou taurinus marsupialis oryx scriptus
## buselaphus 1 2 1 3 1 0 0
## dorcas 0 8 0 0 1 0 1
## gnou 1 0 3 3 1 0 0
## taurinus 0 0 1 16 1 0 0
## marsupialis 0 0 0 0 25 0 1
## oryx 0 0 0 0 0 15 0
## scriptus 0 0 0 0 2 0 19
## strepsiceros 0 0 0 2 0 1 0
## campestris 0 0 0 0 0 0 0
## capreolus 0 0 0 0 0 0 5
## oreotragus 0 0 0 0 0 0 0
## ourebi 0 0 0 0 0 0 4
## caffer 0 0 0 1 0 0 0
## arundinum 0 0 0 0 0 0 0
## ellipsiprymnus 0 0 0 0 0 0 0
## fulvorufulva 0 0 0 0 0 0 2
## leche 0 0 0 0 0 0 1
## equinus 0 0 0 1 0 0 0
## gazella 0 0 0 2 1 0 0
## niger 0 0 0 0 0 0 0
##
## strepsiceros campestris capreolus oreotragus ourebi
## buselaphus 0 0 0 0 0
## dorcas 0 0 0 0 0
## gnou 0 0 0 0 0
## taurinus 1 0 0 0 0
## marsupialis 0 1 0 0 0
## oryx 10 0 0 0 0
## scriptus 0 1 0 0 0
## strepsiceros 19 0 0 0 0
## campestris 0 23 0 0 0
## capreolus 0 0 4 0 0
## oreotragus 0 12 0 0 0
## ourebi 0 0 1 0 1
## caffer 0 0 0 0 0
## arundinum 0 0 0 0 0
## ellipsiprymnus 0 0 0 0 0
## fulvorufulva 0 0 0 0 0
## leche 0 0 0 0 0
## equinus 0 0 0 0 0
## gazella 0 0 0 0 0
## niger 0 0 0 0 0
##
## caffer arundinum ellipsiprymnus fulvorufulva leche
## buselaphus 0 0 4 0 1
## dorcas 0 0 2 0 4
## gnou 0 0 2 1 2
## taurinus 0 0 4 0 0
## marsupialis 0 0 0 0 3
## oryx 1 0 0 0 0
## scriptus 0 0 0 1 2
## strepsiceros 0 0 1 0 0
## campestris 0 0 0 0 0
## capreolus 0 0 0 1 0
## oreotragus 0 0 0 0 0
## ourebi 0 0 0 1 0
## caffer 8 0 2 0 0
## arundinum 0 9 1 12 8
## ellipsiprymnus 0 0 20 0 4
## fulvorufulva 0 0 0 22 5
## leche 0 0 1 2 20
## equinus 0 0 5 0 0
## gazella 0 0 2 0 0
## niger 0 0 9 0 2
##
## equinus gazella niger
## buselaphus 0 0 2
## dorcas 0 0 0
## gnou 0 1 1
## taurinus 0 1 1
## marsupialis 0 0 0
## oryx 0 0 3
## scriptus 0 0 0
## strepsiceros 0 0 1
## campestris 0 0 0
## capreolus 0 0 0
## oreotragus 0 0 0
## ourebi 0 0 0
## caffer 4 0 2
## arundinum 0 0 0
## ellipsiprymnus 0 1 2
## fulvorufulva 0 0 0
## leche 0 0 0
## equinus 0 1 7
## gazella 0 7 3
## niger 0 1 17